package com.whq.thrift.api.web.base.serviceconf.db;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

public interface ModuleInstanceMapper {
	
	@Select("select * from t_module_instance where module_id=#{moduleId}")
	@Results(
		value = {
			/*@Result(property="instanceId", column="instance_id"),*/
			@Result(property="moduleId", column="module_id"),
			@Result(property="ip", column="ip"),
			@Result(property="port", column="port"),
			@Result(property="status", column="status"),
			@Result(property="createTime", column="create_time"),
			@Result(property="updateTime", column="update_time")
		}
	)
	public ModuleInstance getRecordByKey(@Param("moduleId") String moduleId);

	@Insert("INSERT INTO t_module_instance "
			+ " (module_id, ip, port, status, create_time, update_time) "
			+ " VALUES "
			+ " (#{moduleId}, #{ip}, #{port}, #{status}, #{createTime}, #{updateTime})")
	public void addRecord(ModuleInstance moduleInstance);
	
	@SelectProvider(type = ModuleInstanceSqlProvider.class, method = "getSelectRecordsSql")
	@Results(
			value = {
				/*@Result(property="instanceId", column="instance_id"),*/
				@Result(property="moduleId", column="module_id"),
				@Result(property="ip", column="ip"),
				@Result(property="port", column="port"),
				@Result(property="status", column="status"),
				@Result(property="createTime", column="create_time"),
				@Result(property="updateTime", column="update_time")
			}
		)
    public List<ModuleInstance> findRecordsByMap(@Param("moduleId") String moduleId, @Param("beginIndex") int beginIndex, @Param("maxCount") int maxCount);
	
	@SelectProvider(type = ModuleInstanceSqlProvider.class, method = "getSelectCountSql")
    public int findRecordsCount(@Param("moduleId") String moduleId);
	
	@UpdateProvider(type = ModuleInstanceSqlProvider.class, method = "getUpdateSql")
	public void updRecord(ModuleInstance moduleInstance);
	
	@Delete("delete from t_module_instance where module_id=#{moduleId}")
	public void delRecord(@Param("moduleId") String moduleId);
	
	@SelectProvider(type = ModuleInstanceSqlProvider.class, method = "getAllRecordsSql")
	@Results(
			value = {
				/*@Result(property="instanceId", column="instance_id"),*/
				@Result(property="moduleId", column="module_id"),
				@Result(property="ip", column="ip"),
				@Result(property="port", column="port"),
				@Result(property="status", column="status"),
				@Result(property="createTime", column="create_time"),
				@Result(property="updateTime", column="update_time")
			}
		)
    public List<ModuleInstance> getAllRecords();
	
	@Select("select * from t_module_instance where module_id=#{moduleId} and status=#{status}")
	@Results(
		value = {
			/*@Result(property="instanceId", column="instance_id"),*/
			@Result(property="moduleId", column="module_id"),
			@Result(property="ip", column="ip"),
			@Result(property="port", column="port"),
			@Result(property="status", column="status"),
			@Result(property="createTime", column="create_time"),
			@Result(property="updateTime", column="update_time")
		}
	)
	public List<ModuleInstance> getRecordByStatus(@Param("moduleId") String moduleId, @Param("status") int status);
}
